(library (file-system)
  (export file?
          directory?
          readable?
          readable-file?
          readable-directory?
          file-size-in-bytes)
  (import (rnrs base)
          (only (guile)
                lambda* λ
                stat
                stat:type
                stat:size
                access?
                file-exists?))


  (define file?
    (λ (path)
      (and (file-exists? path)
           (eq? (stat:type (stat path)) 'regular))))


  (define directory?
    (λ (path)
      (and (file-exists? path)
           (eq? (stat:type (stat path)) 'directory))))


  (define readable?
    (λ (path)
      (access? path R_OK)))


  (define readable-file?
    (λ (path)
      (and (readable? path)
           (file? path))))


  (define readable-directory?
    (λ (path)
      (and (readable? path)
           (directory? path))))


  (define file-size-in-bytes
    (λ (path)
      (stat:size (stat path)))))
